<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@page import="com.webside.points.wechat.Wechat"%>
<%@page import="com.webside.points.wechat.Constant"%> 
<%
	 //正常跳转
	String code = (String)request.getParameter("code");
  
	String openId = null;
	
	if(code != null){
		Wechat.getOpenId(code,request,response);
	}
	
	if(openId == null){
		openId = (String)request.getSession().getAttribute("openId");
	}
	//如果从其他界面返回时，code已经失效，需要重新请求一次
	
	if(openId == null){
	   response.sendRedirect("../wechat/getWeChatCode");
	   return;
	}  
	String url = Constant.REALM_URL;
	
 %> 
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <link rel="stylesheet" href="../css/amazeui.min.css">
  <link rel="stylesheet" href="../css/wap.css">
   <link rel="stylesheet" href="../css/weui.css" />
    <script src="../js/jquery.min.js"></script>
	<script type="text/javascript" src="../js/timeago.js"></script>
	    <script type="text/javascript"
	src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
		<script src="../js/jssdk.js"></script>
	<link rel="stylesheet" href="../css/dropload.css">
	<script src="../js/dropload.min.js"></script>
		
  <title>问题抢答列表</title>
   <style>
		a{color:#757575;}
		.answer-div{
			float: right;
			padding:3px 10px;
			background:#2ca146;
			border:1px solid #2ca146;
			border-radius: 5px;
			font-size:1.4rem;
			margin-top: 10px;
		}
    </style>
	<script>
		$(function(){
			// 页数
			var page = 0;
			// 每页展示多少个
			var size = 10;
			var openId = $("#openId").val();
			var user = ${user};
			//alert();
			// dropload
			$('.content').dropload({
				scrollArea : window,
				loadDownFn : function(me){
					page++;
					// 拼接HTML
					var result = '';
					$.ajax({
						type: 'post',
						url: '../issue/queryAnswer?page='+page+"&size="+size+"&openId="+openId,
						dataType: 'json',
						success: function(data){
							if(data!=null){
								var arrLen = data.length;
								//alert(page);
								if(arrLen > 0){
									for(var i=0; i<arrLen; i++){
										//出去自己提问
										if(user.id!=data[i].userEntity.id){
											//判断是否停用
											if(data[i].status==1){
												//出去提问其他专家的
												if(data[i].expertIssueId==null||data[i].expertIssueId==user.expertEntity.id){
													result +=   '<li class="am-g am-list-item-desced pet_list_one_block">'
															+'<div class="pet_list_one_info">'
																+'<div class="pet_list_one_info_l">'
																	+'<div class="pet_list_one_info_ico"><img src="'+data[i].userEntity.headUrl+'" alt=""></div>'
																	+'<div class="pet_list_one_info_name">'+data[i].userEntity.wechatId+'</div>'
																+'</div>'
															+'</div>'
															+'<div class=" am-list-main">'
																+'<h3 class="am-list-item-hd pet_list_one_bt"><a href="##" class="">'+data[i].issueContent+'</a></h3>'
																+'<div class="weui-uploader__bd">'
																+'<ul class="weui-uploader__files" id="'+data[i].image+'">'
																+'</ul>'
																+'</div>'
															+'</div>'
															+'<div style="float:left;padding-top:10px;" class="pet_list_tag"><span class="timeago">'+timeago(data[i].createDateFormat)+'</span></div>'
															+'<div class="answer-div">'
																+'<a href="${ctx }/service/character-issue.jsp?issueId='+data[i].id+'&openId='+openId+'&type=answer" style="color:white;" >我要抢答</a>'
															+'</div>'
														+'</li>';
												}
												
											}
										}
										
									}
									
								}else{
									// 锁定
									me.lock();
									// 无数据
									me.noData();
								}
							}else{
								// 锁定
								me.lock();
								// 无数据
								me.noData();
							}
							
							// 插入数据到页面，放到最后面
							$('.am-list').append(result);
							// 每次数据插入，必须重置
							me.resetload();
							
							$(".weui-uploader__files").each(function(){
								 $(this).html("");
								var ul=$(this);
								var imageId = $(this).attr("id");
								if(imageId!=""){
									
									var array=imageId.split(";");
									for(var i=1;i<array.length;i++){
										//alert(array[i]);
										
										var tmpl = '<li class="weui-uploader__file" style="background-image:url(#url#)" onclick="previewImage(this)" id="#value#"></li>';
										tmpl=tmpl.replace("#url#", array[i]);
										//alert(array[i]);
										tmpl=tmpl.replace("#value#", array[i]);
										//alert(tmpl);
										$(ul).append(tmpl);
									}
									
								}
						 });
						},
						error: function(xhr, type){
							//alert('Ajax error!');
							// 即使加载出错，也得重置
							me.resetload();
						}
					});
				}
			});
		});
		function previewImage(e){
			//
			var image = $(e).attr("id").replace("../","<%=url%>");
			//alert(image);
			var images=new Array();;
			
			var li = $(e).parent().children();
			for(var i=0;i<li.length;i++){
				images.push($(li[i]).attr("id").replace("../","<%=url%>"));
			}
			
			wx.previewImage({
				current: image, // 当前显示图片的http链接
				urls: images // 需要预览的图片http链接列表
			});
		}
	</script>
</head>


<body style="background:#ececec">
<input type="hidden" value="<%=openId %>" id="openId">
  <div class="pet_mian" >
    <div class="pet_content pet_content_list">
      <div class="pet_article_like">
        <div class="pet_content_main pet_article_like_delete">
          <div data-am-widget="list_news" class="am-list-news am-list-news-default am-no-layout">
            <div class="am-list-news-bd content">
			  <ul class="am-list">
			  </ul>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <script src="../js/amazeui.min.js"></script>
    <script src="../js/text-calculation.js"></script>

</body>
  </html>